//
//  KNewsPersonalDetailController.m
//  Keping
//
//  Created by apple on 2017/11/25.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "KNewsPersonalDetailController.h"
#import <WebKit/WebKit.h>
#import "KPersonalModel.h"
#import "ZMZWebContentView.h"
#import "NewsPersonalRequest.h"

@interface KNewsPersonalDetailController ()

@property(nonatomic,weak) IBOutlet ZMZWebContentView *webBaseView;
@property(nonatomic,weak) IBOutlet UILabel *personalTitle;
@property(nonatomic,weak) IBOutlet UILabel *personalTime;

@end

@implementation KNewsPersonalDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setUI];
}

- (void)setUI {
    self.view.backgroundColor = kWhiteColor;
    self.title = @"Personal Notice";
    NSString *recommendviewId;
    if (self.recommendView) {
        recommendviewId = self.recommendView.id;
    } else {
        recommendviewId = self.personalID;
    }
    
    [self showLoading];
    WEAKSELF
    NewsPersonalDetailRequest *request = [[NewsPersonalDetailRequest alloc] initWithNewPersonalId:recommendviewId];
    [request startWithCompletionBlockWithSuccess:^(__kindof KBaseRequest * _Nonnull request) {
        [weakSelf hideHUD];
        NSDictionary *dict = request.responseObject;
        if (Dictionary(dict)) {
            [weakSelf showSuccess:@"Success"];
            NSDictionary *recommend = dict[@"glRecommendView"];
            [self.webBaseView setShouldStartLoadBlock:^BOOL(WKWebView *webView, NSURLRequest *request) {
                return YES;
            }];
            [self.webBaseView loadHtmlContentWithHtmlString:recommend[@"content"]];
            self.personalTitle.text = recommend[@"subject"];
            NSTimeInterval second = [recommend[@"createTime"] integerValue] / 1000.0;
            NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
            NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
            fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
            NSString *dateStr = [fmt stringFromDate:date];
            self.personalTime.text  = dateStr;
        } else {
            [weakSelf showErrorText:dict[@"msg"] errCode:[dict[@"statusCode"] integerValue]];
        }
    } failure:^(__kindof KBaseRequest * _Nonnull request) {
        [weakSelf hideHUD];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
